package a1;

import java.util.ArrayList;
import java.util.Scanner;

public class A01_test {
    public static void main(String[] args) {
//        需求：键盘录入一些1~100之间的整数，并添加到集合中，直到集合中所有数据和超过200为止
        ArrayList<Integer> list = new ArrayList<>();
        Scanner sc = new Scanner(System.in);
        while (true) {
            System.out.println("Enter number: ");
            String numStr = sc.nextLine();
            int num = Integer.parseInt(numStr);
            if (num < 0 || num > 100) {
                System.out.println("输入的值不对！");
                continue;
            }
            list.add(num);
            int sum = getSum(list);
            if (sum > 200) {
                System.out.println("已经超过200啦");
                break;
            }
        }
    }

    public static int getSum(ArrayList<Integer> list) {
        int sum = 0;
        for (int i = 0; i < list.size(); i++) {
            sum += list.get(i);
        }
        return sum;
    }
}
